package top.wardyan.wtask.ctrl;

import java.sql.Timestamp;
import java.util.List;

import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Record;

import top.wardyan.base.common.util.DateUtil;
import top.wardyan.common.ctrl.BaseController;
import top.wardyan.wtask.feishu.api.FeishuMsgBusiness;
import top.wardyan.wtask.jobs.FeishuCheckJob;
import top.wardyan.wtask.service.IProcService;
import top.wardyan.wtask.tapd.api.TapdBusiness;

@Path("/story")
public class StoryCtrl extends BaseController{

	private static final cn.hutool.log.Log log = cn.hutool.log.Log.get();

	@Inject FeishuMsgBusiness feishuBusiness;
	@Inject TapdBusiness tapdBusiness;
	@Inject IProcService procService;
	@Inject FeishuCheckJob checkJob;
	
	
	
	public void home(
			Timestamp begin, Timestamp end
			, String man, String cust, String status, String text,Boolean isCust
			, Boolean status1
			, Boolean status2
			, Boolean status3
			, Boolean status4
			, Boolean status5
			, Boolean status6
			, Boolean status7
			, Boolean status8
			, Boolean status9
			, Boolean status10
			, Integer pageNo
			) {
		
		// 如果日期没有赋值,就自动过去一个月
		if(begin == null) {
			begin = DateUtil.range(15);
		}
		if(end == null) {
			end = DateUtil.getCurrentTimestamp();
		}
		end = DateUtil.range(end, 2);
		
		List<Record> storys = procService.yp_query_story(begin, end, man, text, cust, status);
		
		
		List<Record> counts = procService.yp_query_story_count(begin, end, man, text, cust, status, isCust);
		this.set("storydatas", storys);
		this.set("countdatas", counts);

		this.set("man", man);
		this.set("cust", cust);
		this.set("status", status);
		this.set("text", text);
		this.set("isCust", isCust);

		if(status1 != null && status1) {
			List<Record> storydata1 = procService.yp_query_story(begin, end, man, text, cust, "未开始");
			this.set("storydata1", storydata1);
		}
		if(status2 != null && status2) {
			List<Record> storydata2 = procService.yp_query_story(begin, end, man, text, cust, "已拒绝");
			this.set("storydata2", storydata2);
		}

		if(status3 != null && status3) {
			List<Record> storydata3 = procService.yp_query_story(begin, end, man, text, cust, "规划中(未分配任务) ");
			this.set("storydata3", storydata3);
		}

		if(status4 != null && status4) {
			List<Record> storydata4 = procService.yp_query_story(begin, end, man, text, cust, "待实施确认(未分配)");
			this.set("storydata4", storydata4);
		}

		if(status5 != null && status5) {
			List<Record> storydata5 = procService.yp_query_story(begin, end, man, text, cust, "实现中(已分配任务)");
			this.set("storydata5", storydata5);
		}

		if(status6 != null && status6) {
			List<Record> storydata6 = procService.yp_query_story(begin, end, man, text, cust, "任务完成(开发确认OK) ");
			this.set("storydata6", storydata6);
		}

		if(status7 != null && status7) {
			List<Record> storydata7 = procService.yp_query_story(begin, end, man, text, cust, "转测试(任务测试通过)");
			this.set("storydata7", storydata7);
		}

		if(status8 != null && status8) {
			List<Record> storydata8 = procService.yp_query_story(begin, end, man, text, cust, "返工实现中");
			this.set("storydata8", storydata8);
		}

		// 这个必须分页!
		if(status9 != null && status9) {
			List<Record> storydata9 = procService.yp_query_story(begin, end, man, text, cust, "已完结(实施测试OK)");
			this.set("storydata9", storydata9);
		}

		if(status10 != null && status10) {
			List<Record> storydata10 = procService.yp_query_story(begin, end, man, text, cust, "已完成");
			this.set("storydata10", storydata10);
		}

		this.set("status1", status1);
		this.set("status2", status2);
		this.set("status3", status3);
		this.set("status4", status4);
		this.set("status5", status5);
		this.set("status6", status6);
		this.set("status7", status7);
		this.set("status8", status8);
		this.set("status9", status9);
		this.set("status10", status10);
		this.set("begin", begin);
		this.set("end", end);
		
		
		
		this.renderTemplate("story.html");
	}
}
